<?php
/**
 * AgentAccountService
 *
 * @package Akimimi front
 * @author by M.Wang
 */

require_once ('../app/core/services/BaseService.php');
require_once '../app/models/AccountAgentTradeLogsDao.php';
require_once '../app/models/AccountAgentTotalDao.php';
class AgentAccountSercive extends BaseService {

	private $accountAgentTotalDao;

	private $accountAgentTradeLogDao;

    public function __construct(){
        parent::__construct();
        $this->accountAgentTotalDao = new AccountAgentTotalDao($this->dbUtil);
        $this->accountAgentTradeLogDao = new AccountAgentTradeLogsDao($this->dbUtil);
    }

	/**
	 * Get data by `account_agent_trade_logs`.`trade_type` [and `account_agent_trade_logs`.`user_id`]
	 *
	 * @param int $int_tradeType
	 * @param int $int_page
	 * @param int $int_limit
	 * @param int $int_userid
	 * @return array
	 */
	public function getDataByTradeType( $int_tradeType, $int_page, $int_limit, $int_userid = null, $str_otherWhere = null, &$int_countrows=null ){
		$accountAgentTradeLogsDao = new AccountAgentTradeLogsDao( $this->dbUtil );
		$arr_results = $accountAgentTradeLogsDao->getDataByTradeType( $int_tradeType, $int_page, $int_limit, $int_userid, $str_otherWhere );
		if( isset($int_countrows) ){
    		$int_countrows = $this->dbUtil->getLastFoundRows();
    		$int_countrows = $int_countrows[0]['ROWS'];
		}
		return $arr_results;
	}

	/**
	 * Get data by `account_agent_trade_logs`.`id`
	 *
	 * @param int $int_id
	 * @return array
	 */
	public function getTradeLogById( $int_id ){
		$accountAgentTradeLogsDao = new AccountAgentTradeLogsDao( $this->dbUtil);
		$arr_results = $accountAgentTradeLogsDao->getTradeLogById( $int_id );
		if( $arr_results[0] )
			return $arr_results[0];
		return false;
	}

	/**
	 * Get data by `account_agent_trade_logs`.`id`
	 *
	 * @param int $int_id
	 * @return array
	 */
	public function getTradeLogByOrderId( $int_id ){
		$accountAgentTradeLogsDao = new AccountAgentTradeLogsDao( $this->dbUtil);
		$arr_results = $accountAgentTradeLogsDao->getTradeLogByOrderId( $int_id );
		if( $arr_results[0] )
			return $arr_results[0];
		return false;
	}

	/**
	 * get agent's trade total by user id
	 *
	 * @param int $userId
	 * @return array agent trade total
	 */
	public function getAccountAgentTotalByUserId($userId){
		$result = $this->accountAgentTotalDao->getAccountAgentTotalByUserId($userId);
        return $result[0];
	}

	public function saveAccountAgentTradeLog($data){
		$accountAgentTradeLogsDao = new AccountAgentTradeLogsDao( $this->dbUtil);
		return $accountAgentTradeLogsDao->saveAccountAgentTradeLog($data);
	}

	public function updateSN($data,$id){
		$accountAgentTradeLogsDao = new AccountAgentTradeLogsDao( $this->dbUtil);
		$accountAgentTradeLogsDao->updateAccountAgentTradeLog($data,$id);
	}

	public function updateAccountAgentTotal($data,$id){
        $this->accountAgentTotalDao->updateAccountAgentTotal($data,$id);
	}

	public function getPaymentBySN($sn){
		return $this->accountAgentTradeLogDao->getPaymentBySNWithoutStatus($sn);
	}

	public function updateAccountAgentTradeLog($data,$id){
		$this->accountAgentTradeLogDao->updateAccountAgentTradeLog($data,$id);
	}
}

?>
